package com.heima.article.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ZQH
 * @version 1.0
 * @date 2023/8/27 21:49
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    /**
     * 修改文章
     *
     * @param jsonObject
     */
    @Override
    public void updateByJSONObject(JSONObject jsonObject) {
        //enable 0上架 1下架
        Object enable = jsonObject.get("enable");
        boolean isDown = true;
        if (enable.equals(1)){
             isDown = false;
        }
        //修改文章
        this.update(Wrappers.<ApArticleConfig>lambdaUpdate()
        .eq(ApArticleConfig::getArticleId,jsonObject.get("articleId"))
        .set(ApArticleConfig::getIsDown,isDown));
    }
}
